package com.patchmanage.back.controller;


import cn.hutool.core.lang.Dict;
import com.patchmanage.back.entity.AlarmConfig;
import com.patchmanage.back.result.Result;
import com.patchmanage.back.service.IAlarmConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author huizhao
 * @since 2021-04-17
 */
@Api(value = " 告警配置 controller", tags = {"告警配置 Api"})
@RestController
@RequestMapping("/back/alarm-config")
public class AlarmConfigController {
    
    @Autowired
    private IAlarmConfigService alarmConfigService;
    
    /**
     * 获取告警配置接口
     *
     * @param dict
     * @return
     */
    @ApiOperation(value = "获取告警配置更新接口", notes = "获取告警配置更新接口")
    @RequestMapping(value = "getById", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Integer", paramType = "body")
    })
    public Result<AlarmConfig> getById(@ApiIgnore @RequestBody Dict dict) {
        return Result.success(alarmConfigService.getById(dict.getInt("id")));
    }


    /**
     * 新增或修改告警配置更新接口
     * @param alarmConfig
     * @return
     */
    @ApiOperation(value = "新增或修改告警配置更新接口", notes = "新增或修改告警配置更新接口")
    @RequestMapping(value = "saveOrUpdate", method = RequestMethod.POST)
    public Result<Boolean> saveOrUpdate(@RequestBody AlarmConfig alarmConfig){
        return Result.success(alarmConfigService.saveOrUpdate(alarmConfig));
    }
}
